#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include "get_arg.h"



// link with -lboost_filesystem-gcc -lboost_program_options-gcc
// program_options_helper.cpp
//-lboost_filesystem-gcc-d
//-L/usr/local/lib





// my functions
#include <print_error.h>
#include <program_options_helper.h>
#include <stlhelper.h>
#define DEBUG_LEVEL 6
#include <debug_func.h>

using std::string;
using std::cerr;
using std::string;
using std::ofstream;
using std::ifstream;
using std::cerr;
using std::cout;
using std::vector;
using std::max;
using std::sort;
using namespace program_options_helper;
namespace po = boost::program_options_lg;


//_______________________________________________________________________________________

//		process_command_line_options

//				from command line
//				Created [9/13/2001]

//_______________________________________________________________________________________
bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	//
	// checked mandatory arguments
	//
	po::options_description mandatory_args("Mandatory Arguments");
	mandatory_args.add_options()
	("sequences,s", po::value<string>(&args.file_seq)->set_name("FILE"),
						"FILE with sequences in FASTA format.\1"
						"Sequences need not be in order.")
	("kaks_data,k",  	po::value<string>(&args.file_input)->set_name("FILE"),
					   "Kaks data as calculated by seq_pairs_kaks")
	("percent_id,p",  	po::value<float>(&args.percent_id)->set_name("FRACTION"),
					   "Sequence pairs with > this fraction of identical residues.")
	("ds,S"			,  	po::value<float>(&args.dS)->set_name("REAL"),
					   "Sequence pairs with > this dS threshold.")
	("coverage,c",  	po::value<float>(&args.coverage)->set_name("FRACTION"),
					   "Sequence pairs with > this fraction of residues aligned.");


	args.add_std_options();
	po::options_description all_args("");
	all_args.add(mandatory_args).add(args.optional_args);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.0\n"
								   "\tHistory: \n\n"
								   "\tv 1.0\1"
								   "Initial version\1"
								   "12-10-2005\n"
							//			"\tv 1.1\1"
							//			"17-05-2005\1"
							//			"Fixed bug...\1"
							//			"etc.\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
					"Finds sequence pairs with large dS but large % identity and "
					"high alignment coverage.\n";
		print_usage(cerr, string(*argv),	"\n"
											"--sequences FILE\n"
											"--kaks_data data.kaks_res\n"
											"--percent_id FRACTION\n"
											"--coverage FRACTION\n"
											"--dS REAL\n",
							all_args, exe_description, 80);
		return false;
	}
	check_required_options(vm, mandatory_args);

	args.open_err_log();

	return true;
}













